﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace FileMain
{
    /// <summary>
    /// 文件名称替换类
    /// </summary>
    public static class FileNameReplace
    {
        public static ArrayList FileList { get; set; } = new ArrayList();


        /// <summary>
        /// 获取文件夹以及文件夹下面的文件的文件
        /// </summary>
        /// <param name="diroot"></param>

        public static void GetFileList(DirectoryInfo diroot)
        {
            foreach (FileInfo fileName in diroot.GetFiles())
            {
                FileList.Add(fileName.FullName);
            }
            foreach (DirectoryInfo dirSub in diroot.GetDirectories())
            {
                GetFileList(dirSub);
            }
        }



        /// <summary>
        /// 复制文件夹（及文件夹下所有子文件夹和文件）
        /// </summary>
        /// <param name="sourcePath">待移动的文件夹路径</param>
        /// <param name="destinationPath">目标路径</param>
        /// <param name="replacevalue">替换成xx后缀</param>
        public static void CopyDirectory(String sourcePath, String destinationPath, string replacevalue)
        {
            var info = new DirectoryInfo(sourcePath);
            foreach (var fsi in info.GetFileSystemInfos())
            {
                var destName = Path.Combine(destinationPath, fsi.Name);

                if (fsi is FileInfo)
                {
                    File.Move(fsi.FullName, destName.Replace(replacevalue, ""));
                }
                else
                {
                    Directory.CreateDirectory(destName);
                    CopyDirectory(fsi.FullName, destName, replacevalue);
                }
            }
        }

    }
}

